package org.ourgrid.broker.business.schedulerdata.executor;

import java.util.ArrayList;
import java.util.List;

import org.ourgrid.broker.business.schedulerdata.SchedulerData;
import org.ourgrid.broker.response.StartTransferResponseTO;
import org.ourgrid.common.internal.IResponseTO;
import org.w3c.dom.Document;
import org.w3c.dom.Element;

public class StartTransferExecutor extends AbstractSchedulerDataExecutor {
	
	/**
	 * <START_TRANSFER handleId='long' localFileName='String' destinationFileName='String' 
	 * description='String' id='String'/> 
	 */
	public List<IResponseTO> execute(SchedulerData command) {
		
		List<IResponseTO> responses = new ArrayList<IResponseTO>();
		
		Document logDocFile = super.getXMl(command.getXml());
		
		Element element = logDocFile.getDocumentElement();
		
		long handleId = Long.valueOf(element.getAttribute("handleId"));
		String localFileName = element.getAttribute("localFileName");
		String description = element.getAttribute("description");
		String id = element.getAttribute("id");
		
		StartTransferResponseTO to = new StartTransferResponseTO();
		
		to.setHandleId(handleId);
		to.setLocalFileName(localFileName);
		to.setDescription(description);
		to.setId(id);
		
		responses.add(to);
		
		return responses;
	
	}
}
